package com.sales.service.view;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;

/**
 * SalesServiceActivity is a class that extends Activity. This Activity is set a Launcher mode.
 * On call of this activity, the ServiceThreadPool class is called by it method getInstance().
 * Hence in the onCreate(Bundle...) method, the above function is done. 
 * @author Sega
 *
 */
public class BaseActivity extends Activity{
	
	/**
	 * Strings for debugging process by log.i method
	 */
	private static final String TagProject = "SalesService";
	private static final String TagPage = "Base ::";
	
	/**
	 * declaring int ID for progress dialog.
	 */
	protected static final int DIALOG_ID_PROGRESS = 1;
	
	/* (non-Javadoc)
	 * @see android.app.Activity#onCreate(android.os.Bundle)
	 * 
	 * The layout is set by the setContentView() method.
	 * The instance getting method of the singleton class is called.
	 */
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		Log.i(TagProject, TagPage);
		
	}
	
	/**
	 * To hide the progress dialog.
	 */
	public void hideProgress(){
		try {
			removeDialog(DIALOG_ID_PROGRESS);
		} catch (IllegalArgumentException iae) {
			//Its not an issue if the dialog is already hidden.
		}
	}
	
	/* (non-Javadoc)
	 * @see android.app.Activity#onCreateDialog(int)
	 * 
	 * to create the progress dialog.
	 * message is set to "Please wait..."
	 * its not cancelable.
	 * 
	 */
	protected Dialog onCreateDialog(int id){
		hideProgress();
		switch (id) {
		case DIALOG_ID_PROGRESS:
			ProgressDialog dialog = new ProgressDialog(this);
			dialog.setMessage("Please wait...");
			dialog.setCancelable(false);
			dialog.setIndeterminate(true);
			return dialog;
		default:
			return super.onCreateDialog(id);
		}
	}
}